colors <- c("firebrick", "darkorange", "forestgreen",
"royalblue", "darkorchid")
fig <- plot_ly(data = data_07,
x = ~gdpPercap)
fig <- fig %>%
add_trace(type = "scatter",
mode = "markers",
y = ~lifeExp,
color = ~continent,
colors = colors,
marker = list(size = 10,
opacity = 0.8,
line = list(color = "black",
width = 1)),
text = ~paste("Country: ", country,
"\nContinent:", continent,
"\nLife Expectancy:", lifeExp,
"\nGDP Per Capita:", scales::dollar(gdpPercap)),
hoverinfo = "text")
fig <- fig %>%
layout(title = "Relationship Between Economic Development\nand Life Exepctancy (2007)",
yaxis = list(title = "Life Exepctancy",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "GDP Per Capita (USD)",
zeroline = FALSE,
showline = TRUE))
figfig <- plot_ly(data = data_multi,
x = ~year)
fig <- fig %>%
add_trace(type = "scatter",
mode = "lines",
y = ~mean_lifeExp,
name = "Mean",
line = list(color = "rgba(51, 0, 51, .8)",
width = 2),
text = ~paste("Mean: ", round(mean_lifeExp, 1)),
hoverinfo = "text")
fig <- fig %>%
add_trace(type = "scatter",
mode = "lines",
y = ~max_lifeExp,
name = "Maximum",
line = list(color = "rgba(0, 0, 51, .8)",
width = 2,
dash = "dash"),
text = ~paste("Maximum: ", round(max_lifeExp, 1)),
hoverinfo = "text")
fig <- fig %>%
add_trace(type = "scatter",
mode = "lines+markers",
y = ~min_lifeExp,
name = "Minimum",
line = list(color = "rgba(0, 153, 76, .6)",
width = 2),
marker = list(size = 10,
color = "rgba(0, 153, 76, .6)",
line = list(color = "rgba(0, 102, 0, .8)",
width = 1)),
text = ~paste("Minimum: ", round(min_lifeExp, 1)),
hoverinfo = "text")
fig <- fig %>%
layout(title = "Life Expectancy Over Time",
yaxis = list(title = "Life Exepctancy",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "",
zeroline = FALSE,
showline = TRUE),
hovermode = "x unified")
figfig <- plot_ly(data = data_means,
x = ~year)
fig <- fig %>%
add_trace(type = "scatter",
mode = "lines",
y = ~mean_lifeExp + sd_lifeExp,
line = list(color = 'transparent'),
showlegend = FALSE,
hoverinfo = "skip")
fig <- fig %>%
add_trace(type = "scatter",
mode = "lines",
y = ~mean_lifeExp - sd_lifeExp,
fill = 'tonexty',
fillcolor = 'rgba(0, 100, 80, 0.2)',
line = list(color = 'transparent'),
showlegend = FALSE,
hoverinfo = "skip")
fig <- fig %>%
add_trace(type = "scatter",
mode = "lines",
y = ~mean_lifeExp,
line = list(color='rgb(0, 100, 80)'),
name = "Average")
fig <- fig %>%
layout(title = "Life Expectancy Over Time",
yaxis = list(title = "Life Exepctancy",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "",
zeroline = FALSE,
showline = TRUE))
figfig <- plot_ly(data = data_means,
type = "bar",
x = ~year,
y = ~mean_lifeExp,
marker = list(color = "firebrick",
opacity = 0.8,
line = list(color = "black", width = 1)),
text = ~paste("The mean worldwide life expectancy in", year,
"was", round(mean_lifeExp, 2), "years"),
hoverinfo = "text")
fig <- fig %>%
layout(title = "Life Expectancy Over Time",
yaxis = list(title = "Life Exepctancy",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "Year",
zeroline = FALSE,
showline = TRUE))
figfig <- plot_ly(data = data_means_cont,
type = "bar",
x = ~continent,
y = ~`1952`,
name = "1952 Avg",
marker = list(color = "firebrick",
opacity = 0.8,
line = list(color = "black", width = 1)),
text = ~paste("In 1952 the life expectancy in", continent,
"was", round(`1952`, 2), "years"),
hoverinfo = "text")
fig <- fig %>%
add_trace(y = ~`1972`,
name = "1972 Avg",
marker = list(color = "forestgreen"),
text = ~paste("In 1972 the life expectancy in", continent,
"was", round(`1972`, 2), "years"),
hoverinfo = "text")
fig <- fig %>%
add_trace(y = ~`1992`,
name = "1992 Avg",
marker = list(color = "royalblue"),
text = ~paste("In 1992 the life expectancy in", continent,
"was", round(`1992`, 2), "years"),
hoverinfo = "text")
fig <- fig %>%
layout(title = "Life Expectancy Over Time",
yaxis = list(title = "Life Exepctancy",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "",
zeroline = FALSE,
showline = TRUE))
figfig <- plot_ly(data = data_pop,
type = "bar",
x = ~year,
y = ~Asia,
name = "Asia",
marker = list(color = 'rgba(204,0,0,0.6)',
line = list(color = 'rgb(204,0,0)', width = 1.5)),
text = ~paste("Continent: Asia",
"\nPopulation: ", scales::comma(Asia)),
hoverinfo = "text")
fig <- fig %>%
add_trace(y = ~Africa,
name = "Africa",
marker = list(color = 'rgba(255,128,0,0.6)',
line = list(color = 'rgb(204,128,0)', width = 1.5)),
text = ~paste("Continent: Africa",
"\nPopulation: ", scales::comma(Africa)),
hoverinfo = "text")
fig <- fig %>%
add_trace(y = ~Americas,
name = "Americas",
marker = list(color = 'rgba(0,102,0,0.6)',
line = list(color = 'rgb(0,102,0)', width = 1.5)),
text = ~paste("Continent: Americas",
"\nPopulation: ", scales::comma(Americas)),
hoverinfo = "text")
fig <- fig %>%
add_trace(y = ~Europe,
name = "Europe",
marker = list(color = 'rgba(0,51,102,0.6)',
line = list(color = 'rgb(0,51,102)', width = 1.5)),
text = ~paste("Continent: Europe",
"\nPopulation: ", scales::comma(Europe)),
hoverinfo = "text")
fig <- fig %>%
add_trace(y = ~Oceania,
name = "Oceania",
marker = list(color = 'rgba(51,0,102,0.6)',
line = list(color = 'rgb(51,0,102)', width = 1.5)),
text = ~paste("Continent: Oceania",
"\nPopulation: ", scales::comma(Oceania)),
hoverinfo = "text")
fig <- fig %>%
layout(title = "Population Over Time",
yaxis = list(title = "Population",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "Year",
zeroline = FALSE,
showline = TRUE),
barmode = "stack")
figcolors <- c("firebrick", "darkorange", "forestgreen",
"royalblue", "darkorchid")
fig <- plot_ly(data = data_07,
type = "box",
quartilemethod = "exclusive",
y = ~lifeExp,
color = ~continent,
colors = colors)
fig <- fig %>%
layout(title = "Life Expectancy, 2007",
yaxis = list(title = "Life Expectancy",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "",
zeroline = FALSE,
showline = TRUE))
figfig <- plot_ly(data = data_07,
type = "box",
boxpoints = "all",
jitter = 0.3,
pointpos = -1.8,
quartilemethod = "exclusive",
y = ~lifeExp,
name = "Life expectancy",
text = ~country)
fig <- fig %>%
layout(title = "Life Expectancy, 2007",
yaxis = list(title = "Life Expectancy",
zeroline = FALSE,
showline = TRUE),
xaxis = list(title = "",
zeroline = FALSE,
showline = TRUE))
figtickfont <- list(family = "Old Standard TT, serif",
size = 14,
color = "black")
axisfont <- list(family = "Arial, sans-serif",
size = 18,
color = "grey")
xaxis <- list(title = "",
autotick = FALSE,
tickfont = tickfont,
tickangle = -45,
ticks = "outside",
range = c(1950, 2010),
tick0 = 1952,
dtick = 5,
ticklen = 5,
tickwidth = 2,
tickcolor = toRGB("blue"),
showline = TRUE,
linecolor = toRGB("blue"),
linewidth = 2)
yaxis <- list(title = "Life Exepctancy",
titlefont = axisfont,
autotick = FALSE,
tickfont = tickfont,
ticks = "outside",
range = c(-10, 70),
tick0 = -10,
dtick = 5,
ticklen = 5,
tickwidth = 2,
tickcolor = toRGB("blue"),
showline = TRUE,
linecolor = toRGB("blue"),
linewidth = 2,
zeroline = TRUE,
zerolinecolor = toRGB("black"),
zerolinewidth = 1)
fig <- fig %>%
layout(xaxis = xaxis,
yaxis = yaxis)
figxaxis <- list(ticktext = list("Initial Measurement\n(1952)",
"MMR Vaccine\n(1971)",
"Most Recent\n(2007)"),
tickvals = list(1952, 1971, 2007),
tickmode = "array")
yaxis <- list(tickformat = "%")
fig <- fig %>%
layout(xaxis = xaxis,
yaxis = yaxis)
figfig <- fig %>%
add_trace(y = ~`1992` * 1.05,
name = "1997 Projection",
text = ~paste("In 1997 the life expectancy in", continent,
"could be", round(`1992` * 1.2, 2), "years"),
marker = list(color = "lightgray"),
showlegend = FALSE)
figfig <- plot_ly(data = data_multi,
x = ~year)
fig <- fig %>%
add_trace(type = "scatter",
mode = "lines+markers",
y = ~mean_lifeExp,
name = "Life Expectancy",
line = list(color = "rgba(0, 153, 76, .6)",
width = 2),
marker = list(size = 10,
color = "rgba(0, 153, 76, .6)",
line = list(color = "rgba(0, 102, 0, .8)",
width = 1)),
error_y = ~list(array = sd_lifeExp,
color = "gray"),
text = ~paste("Mean: ", round(mean_lifeExp, 1),
"\nSD: ", round(sd_lifeExp, 1)),
hoverinfo = "text")
fig